home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Compendium Deluxe 2
/
LSD and 17bit Compendium Deluxe - Volume II.iso
/
a
/
prog
/
asmsrc
/
thesource-7.lha
/
Source
/
DefFunc.lha
/
DefFunc
/
demo.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-14
|
1KB
|
58 lines
/*********************************************************
*
* example program of useing defunc (Ke Jin 1993)
*
*********************************************************/
#include <stdio.h>
#include <math.h>
#include <defunc.h>
int main()
{
double (*fp)();
char expr[128];
double x;
matha2z(); /* portable functions in math lib into token table */
printf("\n\tEnter a expression please.\n");
for(;;)
{
printf("\n\tinput > ");
fgets(expr, 127, stdin);
expr[strlen(expr)-1]='\0'; /* strip off the '\n' on end */
if(strncmp(expr, "quit", 4)==0||
strncmp(expr, "exit", 4)==0)
{
printf("\n\t\t--------- Bye! ---------\n\n");
return 0;
}
fp = dfopen(expr);
if(fp==0) {
if(exparserror!=0)
printf("\t\t%s\n", exparserror);
else
printf("\t\tempty expression body\n");
exparserror = 0;
printf("\n\t\tcurrent arguments are %s, %s\n",
getarguname(1), getarguname(2));
continue;
}
printf("\t\t%s\t\t%s\n", getarguname(1), expr);
for(x=0.0;x<1.0;x=x+0.1)
{
printf("\t\t%f\t%f\n", x, fp(x,0));
}
printf("\n\t\tcurrent arguments are %s, %s\n",
getarguname(1), getarguname(2));
dfclose(fp);
}
}